package de.tabuma.formcreator.javascript.logik;

import de.tabuma.formcreator.entity.*;
import de.tabuma.formcreator.logik.*;

import java.util.logging.*;
import java.util.*;

/**
  * @author $Author: $
  * @version $Revision: $
  * @since $Date: $
 */
public class PersistentFacade {
    private static final Logger log = Logger.getLogger(SendFacade.class.getName());

    public static String getPersistObject(FormStructur formStructur) {
        String str = EntityFacade.getAllObject(formStructur);
        return str;
    }

    public static String getCreateMethod(FormStructur formStructur) {
        String str = "function createObject"+formStructur.getId()+"() {\n";
        str += "Object"+formStructur.getId()+"=Object"+formStructur.getId()+"();\n";
        for(int i=0;i<formStructur.getFormStructur().size();i++) {
            FormStructur fs = formStructur.getFormStructur().get(i);
            if(fs.isSimpleType()) {
                str += "Object"+formStructur.getId()+".setObject"+fs.getId()+"(document.getElementsByName(\"element"+fs.getId()+"\")[0].value);\n";
            }
        }
        if(formStructur.getHeadStructur()!=null) {
            str += "Object"+formStructur.getHeadStructur().getId()+".addObject"+formStructur.getId()+"(Object"+formStructur.getId()+");\n";
        }
        str += "}\n";
        return str;
    }

    public static String getRemoveMethod(FormStructur formStructur) {
        String str = "\tfunction removeObject"+formStructur.getId()+"(i) {\n";
        str += "\t\tObject"+formStructur.getHeadStructur().getId()+"\n";
        str += "\t}\n";
        return str;
    }
}